<%@ page import="com.ld.businesscard_manage.service.UserService" %>
<%@ page import="com.ld.businesscard_manage.service.impl.UserServiceImpl" %>
<%@ page import="com.ld.businesscard_manage.bean.User" %>
<%@ page import="com.ld.businesscard_manage.service.BusinessCardService" %>
<%@ page import="com.ld.businesscard_manage.service.impl.BusinessCardServiceImpl" %><%--
  Created by IntelliJ IDEA.
  User: 刘邓
  Date: 2023-06-01
  Time: 21:52
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>修改用户结果</title>
</head>
<body>
<%!
    private UserService userService = new UserServiceImpl();
	private BusinessCardService cardService = new BusinessCardServiceImpl();
%>
<%
    request.setCharacterEncoding("utf-8");
    User user0 = (User)(session.getAttribute("currentUser"));
	Integer id = user0.getId();
	String userName = user0.getUsername();
	String account = new String(userName);
	String userName0 = userName;
	String password = user0.getPassword();
	Integer status = user0.getStatus();
	if (!request.getParameter("username").equals("")) {
        userName = request.getParameter("username");
    };
	if(!request.getParameter("password").equals("")){
        password = request.getParameter("password");
    }
    User userByName = userService.getUserByName(userName);
    if(userByName != null && !userByName.getUsername().equals(userName0)){
        out.println("该用户已经存在");
    }else {
        User user = new User(id, userName, password, status);
        int i = userService.changeUserById(user);
		int j = cardService.changeCardsByAccount(user,account);
        if (i == 0 || j == 0) {
            out.println("<h1>修改失败,请稍后重试</h1>");
        } else {
            out.println("<h1>修改成功</h1>");
        }
    }
	out.println("<a href='/home/manageUser.jsp'>返回用户管理页</a>");
%>
</body>
</html>
